/**
 * table 处理空值， slot 未使用时生效
 * @param _row
 * @param _column
 * @param cellValue
 * @returns
 */
export const emptyFormatter = (_row: any, _column: any, cellValue: any) =>
  emptyText(cellValue)

/**table时间格式化 */
export const emptyFormatterUnix = (_row: any, _column: any, cellValue: any) => {
  if (!isNaN(+cellValue) && typeof +cellValue === 'number') {
    return formatUnix(+cellValue)
  }
  return emptyText(cellValue)
}

/**
 * 处理空值
 * @param value 原数据
 * @returns
 */
export const emptyText = (value: any, emptySign: string = '-') => {
  if (
    value === '' ||
    value === void 0 ||
    value === null ||
    (Array.isArray(value) && !value.length)
  ) {
    return emptySign
  }
  return value
}

export const tooltipOption = {
  placement: 'top-start',
  popperClass: 'basic-tooltip'
} as const
/**
 * 获取由LabelValue组成的数组里指定value的label
 * @param options
 * @param value
 * @returns
 */
export const getOptionsLabel = <T extends LabelValue>(
  options: T[],
  value: string | number
) => {
  return emptyText(options.find(item => item.value === value)?.label)
}
